package be.lreenaers.kaktus.client;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;

public class PathWay {
	private Tree tree;
	private HorizontalPanel panel;
	private Label separator = new Label(">");
	public PathWay(Tree tree){
		this.tree = tree;
		
	}
	public HorizontalPanel getPanel(){
		this.panel = new HorizontalPanel();
		this.panel.setStyleName("path-GW");
		//this.panel.setSpacing(5);
		ArrayList<Anchor> parents = new ArrayList<Anchor>();
		TreeItem itm = this.tree.getSelectedItem();
		Anchor anch = new Anchor(itm.getText());
		parents.add(anch);
		TreeItem parent = itm.getParentItem();
		while(parent != null){
			parents.add(new Anchor(parent.getText()));
			parent = parent.getParentItem(); 
		}
		System.out.println(parents.size());
		for(int i = parents.size()-1;i>=0;i--){
			System.out.println(parents.get(i).getText());
			if(i==0){
				System.out.println("was 0");
				this.panel.add(parents.get(i));
			}else{
				System.out.println("was not 0");
				this.panel.add(parents.get(i));
				this.panel.add(separator);

			}
		}
		return this.panel;
	}
}
